package net.wnb.mineclearance.ui;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class MainWindow extends JFrame {

	/**
	 * 
	 */
	public static final int MARGIN_HORIZONTAL = 5;
	public static final int MARGIN_VERTICAL = 10;
	
	private static final long serialVersionUID = 1L;	
	private JComponent currentPane;
	private static MainWindow instance;
	private static Object syncRoot = new Object();
	
	private MainWindow(String title){
		super(title);
	}
	
	//替换中央的面板
	public void setPane(JComponent pane){
		if(currentPane != null){
			remove(currentPane);
		}
		
		add(pane);
		currentPane = pane;
		setSize(pane.getWidth() + MARGIN_HORIZONTAL, pane.getHeight() + MARGIN_VERTICAL);
	}
	
	//获取该类唯一实例
	public static MainWindow getInstance(){
		if(instance == null){
			synchronized(syncRoot){
				if(instance == null){
					instance = new MainWindow("扫雷");
				}
			}
		}
		
		return instance;
	}

}
